﻿@inherits RadzenComponent
@using Radzen
@using Radzen.Blazor.Rendering;
@if (Visible)
{
    <div @ref="@Element" style="@Style" aria-valuemax="@Max" aria-valuemin="0" role="progressbar" @attributes="Attributes" class="@GetCssClass()"
         aria-valuenow="@Value" id="@GetId()">
        <div class="rz-progressbar-value rz-progressbar-value-animate" style="@($"width: {Math.Min(Value / Max * 100, 100).ToInvariantString()}%;")"></div>
        @if (ShowValue)
        {
            <div class="rz-progressbar-label">@Value@Unit</div>
        }
    </div>
}
@code {
    protected override string GetComponentCssClass()
    {
        return Mode == ProgressBarMode.Determinate ? "rz-progressbar rz-progressbar-determinate" : "rz-progressbar rz-progressbar-indeterminate";
    }

    [Parameter]
    public ProgressBarMode Mode { get; set; }

    [Parameter]
    public string Unit { get; set; } = "%";

    [Parameter]
    public double Value { get; set; }

    [Parameter]
    public double Max { get; set; } = 100;

    [Parameter]
    public bool ShowValue { get; set; } = true;

    [Parameter]
    public Action<double> ValueChanged { get; set; }
}
